//
//  ViewController.m
//  xml解析Demo
//
//  Created by byztl on 2017/7/19.
//  Copyright © 2017年 byztl. All rights reserved.
//

#import "ViewController.h"
#import <AFNetworking.h>
#import "XMLDictionary.h"

@interface ViewController ()<NSXMLParserDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loadData{
    NSDictionary *params = @{@"appCode":@"102",
                             @"appSign":@"A1992687C1EA1C33632D951D89C8D7BA",
                             @"intCompID":@"1"
                             };
    NSString *url = @"http://oa.kswsljt.com:81//Service/OAMobileService.asmx/GetCompanyTree?";
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    mgr.responseSerializer = [AFXMLParserResponseSerializer serializer];
    [mgr POST:url parameters:params success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        NSXMLParser *parser = responseObject;
//        parser.delegate = self;
//        [parser parse];
        XMLDictionaryParser *parser = [XMLDictionaryParser sharedInstance];
        NSDictionary *dict = [parser dictionaryWithParser:responseObject];
        NSLog(@"Data:%@",dict);
        NSDictionary *dict1 = [dict valueForKey:@"__text"];
        NSLog(@"Data:%@",dict1);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"失败了");
    }];
}

//解析
- (void)parserDidStartDocument:(NSXMLParser *)parser{
//    NSLog(@"1,开始文档");
}


- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary<NSString *,NSString *> *)attributeDict{
//    self.
    
}
@end
